package gov.dhs.cis.soa.data;

import gov.dhs.cis.soa.Constants;
import gov.dhs.cis.soa.Utils;
import gov.dhs.cis.soa.Constants.EntityType;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;


public class Service extends AbstractSOAData {
	public static final String STEREO_TYPE = "Service";

	public int id;
	public String name;
	public transient String descText;
	public String stereotype;
	public String wipt;
	public String release;
	public int maturity;
	public String applications;
	public String extsystems;
	public String otherservices;

	public transient String l3busprocname;
	
	public String servDefID;
	public String agent;
	public String exposure;
	public String realization;
	public String inthostcfg;
	public String intesbendpt;
	public transient String designAspects;
	public Description desc;
	
	public transient Timestamp createdDt = new Timestamp(System.currentTimeMillis());

	public List<ServiceOperation> opList = null;
	
	@Override
	public String toString() {
		return "Services [id=" + id + ", name=" + name + "]";
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Service other = (Service) obj;
		if (id == other.id && name.equalsIgnoreCase(other.name))
			return true;
		return false;
	}
	
	public void createDescription() {
		StringBuffer txt = new StringBuffer();
		if(Utils.isEmpty(descText))
			descText = "";
		txt.append(Constants.NL+"Description = " + descText);
		if(Utils.isEmpty(designAspects))
			designAspects = "";
		txt.append(Constants.NL+"Design Aspects = " + designAspects);
		if(Utils.isEmpty(l3busprocname))
			l3busprocname = "";
		txt.append(Constants.NL+"Business Process = " + l3busprocname);
		
		desc = Utils.prepareDescObj(txt.toString(), EntityType.SERV);
	}
	
/*
	public void setDataList(List<RelatedDataReference> inList, List<RelatedDataReference> outList) {
		if(dataList == null)
			dataList = new ArrayList<RelatedDataReference>();
		else
			dataList.clear();
		if(inList != null && inList.size() > 0)
			dataList.addAll(inList);
		if(outList != null && outList.size() > 0)
			dataList.addAll(outList);
	}
	*/
	
	public void add(ServiceOperation sOp) {
		if(opList == null)
			opList = new ArrayList<ServiceOperation>();
		opList.add(sOp);
	}
	
//	public static String getUMLId(int entityId) {
//	return EntityType.SERV + "_" + entityId;
//}

	@Override
	public long getId() {
		return id;
	}
	@Override
	public String getHashableId() {
		return name;
	}
	
	@Override
	public EntityType getUMLType() {
		return EntityType.SERV;
	}
}
